package com.boot2.core.web;

import lombok.SneakyThrows;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.stereotype.Component;

/**
 * @author zhangweilin
 * @Description: 默认的RestTemplate拦截器，啥也不做
 * @date 2020/7/17
 */
@Component
public class DefaultRestTemplateInterceptor extends AbstractRestTemplateInterceptor{

    static final String defaultBaseUrl = "default";

    @Override
    public String getBaseUrl() {
        return defaultBaseUrl;
    }

    @SneakyThrows
    @Override
    public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) {
        traceRequest(request, body);
        ClientHttpResponse clientHttpResponse = execution.execute(request, body);
        clientHttpResponse = warpResponse(  request,clientHttpResponse);
        // 保证请求继续被执行
        return clientHttpResponse;
    }
}
